﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Ionic.Zip;
using RuneLog.Stats;

namespace RuneLog.AdventerersLog
{
    class RunescapeImageList 
    {
        private static List<string> nameIDs = new List<string>();
        public static int GetID(string name)
        {
            return nameIDs.IndexOf(name);
        }
        public static Image GetIcon(int id)
        {
            return imageList.Images[id];
        }
        public static Image GetIcon(string name)
        {
            return imageList.Images[nameIDs.IndexOf(name)];
        }
        private static ImageList imageList = new ImageList();
        public static ImageList AsImageList
        {
            get
            {
                return imageList;
            }
        }
        static RunescapeImageList()
        {
            nameIDs.Add("info");
            imageList.Images.Add(SystemIcons.Information);
            using (ZipFile zip = ZipFile.Read("resources/skills.zip"))
            {
                foreach (ZipEntry z in zip)
                {
                    nameIDs.Add(z.FileName.Substring(0,z.FileName.Length-4));
                    imageList.Images.Add(Icon.FromHandle(new Bitmap(z.OpenReader()).GetHicon()));
                }
                var defbmpt = new Bitmap(imageList.Images[GetID("Attack")]);
                defbmpt.MakeTransparent(defbmpt.GetPixel(0, 0));

                var defimg = imageList.Images[GetID("Attack")];
                defimg.RotateFlip(RotateFlipType.RotateNoneFlipX);

                Graphics g = Graphics.FromImage(defimg);
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                g.DrawImage(defbmpt, new Point(0, 0));

                var deficon = Icon.FromHandle(new Bitmap(defimg).GetHicon());

                nameIDs.Add("default kill");
                imageList.Images.Add(deficon);
            }
        }
    }
}
